<?

class Smutty_Data {

	var $postData;

	/**
	 *  constructor
	 *
	 */

	function Smutty_Data() {
		$this->postData = Smutty_Utils::copyAssoc( $_POST );
		$_POST = null;
	}

	/**
	 *  static method for fetching the instance of this class (as
	 *  it's designed to be a singleton)
	 *
	 *  @return Smutty_Data the class instance
	 *
	 */

	function getInstance() {
		static $instance;
		if ( $instance == null )
			$instance = new Smutty_Data();
		return $instance;
	}

	/**
	 *  returns the value of the specifed variable as
	 *  an integer (false if it's not valid)
	 *
	 *  @param [name] name of variable to fetch
	 *  @return int integer value
	 *
	 */

	function int( $name ) {
		return Smutty_Data::getInt( $this->postData[$name] );
	}

	/**
	 *  this method can be used staticly to validate data
	 *
	 *  @param [value] the value to validate
	 *  @return int
	 *
	 */

	function getInt( $value ) {
		return (int) $value;
	}

	/**
	 *  returns an integer with a padded 0 if it
	 *  is less than 10
	 *
	 *  @param [name] the name of the variable
	 *  @return int
	 *
	 */

	function intPad( $name ) {
		$value = $this->int( $name );
		return ( $value < 10 ) ? "0$value" : $value;
	}

	/**
	 *  returns the value of the specifed variable
	 *  as a string.
	 *
	 *  @param [name] name of variable
	 *  @return String string value
	 *
	 */

	function string( $name ) {
		return $this->postData[ $name ];
	}

	/**
	 *  returns the current date and time formatted as a string
	 *  for use with the database
	 *
	 *  @return String
	 *
	 */

	function getDate() {
		$db = Smutty_Database::getInstance();
		return $db->getCurrentDate();
	}

}

?>